package org.cloud.api.auth.exception;

import org.cloud.common.exception.SlothCloudException;
import org.cloud.common.model.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 系统层级最外层的异常处理器
 * @author wangyuan
 * @since 2019年6月7日 上午4:26:24
 *
 */
@RestControllerAdvice
public class SlothExceptionHandler {
	
	private static Logger logger = LoggerFactory.getLogger(SlothExceptionHandler.class);
	
	@ExceptionHandler(SlothCloudException.class)
	public R handleSlothCloudException(SlothCloudException e){
	    logger.error("服务器错误，原因是：", e);
		return R.error(e.getCode(), e.getMessage());
	}

	@ExceptionHandler(Exception.class)
	public R handleException(Exception e){
		logger.error("服务器错误，原因是：", e);
		return R.error("系统异常，原因是：" + e.getMessage());
	}
}
